package DL;

/**
 * Created by xwj on 2017/11/17.
 */
public class Map3DTo2D {
    static final double S_PI = 3.14159265358979323846;
    static final double S_PI_2 = 1.57079632679489661923;
    static final double S_EPS = 1.0e-6;
    static final int    S_PAD_MAX = 16;
    static final double S_ICOSA_GOLDEN = ((Math.sqrt(5.0)+1.0)/2.0);

    public static SPos map3DTo2D(SPos pSPosIn,int iFaceWidth,int iFaceHeight)
    {
        SPos pSPosOut=new SPos();
        double x = pSPosIn.x;
        double y = pSPosIn.y;
        double z = pSPosIn.z;

        pSPosOut.faceIdx = 0;
        pSPosOut.z = 0;
        //yaw;
        pSPosOut.x = (double)((S_PI-Math.atan2(z, x))*iFaceWidth/(2*S_PI));
        pSPosOut.x -= 0.5;

        double len = Math.sqrt(x*x + y*y + z*z);
        //pitch;
        pSPosOut.y = (double)((len < S_EPS? 0.5 : Math.acos(y/len)/S_PI)*iFaceHeight);
        pSPosOut.y -= 0.5;
        return pSPosOut;
    }

}
